package com.origin.niuke.string;

import java.util.PriorityQueue;

/**
 * 拼接所有的字符串产生字典序最小的字符串
 * 算法：字符串
 *
 * @author yezh
 * @date 2023/1/30 21:38
 */
public class NC85 {

    public String minString(String[] strs) {
        // write code here
        PriorityQueue<String> queue = new PriorityQueue<>((str1, str2) -> (str1 + str2).compareTo(str2 + str1));
        for (String str : strs) queue.offer(str);
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < strs.length; i++) ans.append(queue.poll());
        return ans.toString();
    }

}
